package com.smh.demo1.a06;

import com.smh.demo1.common.LogColour;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;

/**
 * @author shiminghui
 * @date 2025/4/12 10:52
 * @description: TODO
 */
public class Config2 implements BeanNameAware, ApplicationContextAware, InitializingBean {
    private static final Logger log = LoggerFactory.getLogger(Config2.class);

    /**
     * spring 内部的类一般会用Aware接口来实现一些初始化操作,因为他是内置的,可以保证有效性,必定会执行
     */
    @Override
    public void setBeanName(String s) {

    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info(LogColour.BLUE + "beanFactoryPostProcessor use InitializingBean" + LogColour.RESET);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.info(LogColour.BLUE + "beanFactoryPostProcessor use ApplicationContextAware" + LogColour.RESET);
    }

    @Bean
    public BeanFactoryPostProcessor beanFactoryPostProcessor() {
        return beanFactory -> {
            log.info(LogColour.BLUE + "beanFactoryPostProcessor use Bean" + LogColour.RESET);
        };
    }

}
